//
//  Demo2ViewController.m
//  Demo
//
//  Created by Tang Boss on 11/12/2017.
//  Copyright © 2017 HandeIdealVison. All rights reserved.
//

#import "Demo2ViewController.h"
#import <HandeAR/HandeARViewController.h>
#import <HandeAR/HandeAR.h>
#import "HWScanViewController.h"
#import "NSBundle+Demo.h"
//#import "WXMediaMessage+messageConstruct.h"
//#import "SendMessageToWXReq+requestWithTextOrMediaMessage.h"
#import <AVFoundation/AVFoundation.h>
#import <MediaPlayer/MediaPlayer.h>

static NSString *kImageTagName = @"WECHAT_TAG_JUMP_APP";
static NSString *kMessageExt = @"这是第三方带的测试字段";
static NSString *kMessageAction = @"<action>dotalist</action>";

@interface Demo2ViewController ()
@property (nonatomic, strong) HWScanViewController *vc;
@end

@implementation Demo2ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
//    [HandeAR preSetup];
    self.title = @"Demo";
    // Do any additional setup after loading the view.
    self.vc = [[HWScanViewController alloc] init];
    [self.view addSubview:self.vc.view];
    [self.view sendSubviewToBack:self.vc.view];
    [[NSBundle mainBundle] setCrack:YES];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//        [HandeAR preSetup];
    });
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [self.vc start];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)showQR:(id)sender {
}

- (IBAction)showAR:(id)sender {
//    [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryAmbient error:nil];
    [HandeAR setDelegate:self];
//    [HandeAR saveImageWhenSnapshot:NO];
    [HandeAR setLoginStatus:YES];
    [HandeAR setPublishTime:@"2017-12-11 12:01:01"];
    [HandeAR setARResourceURL:@"http://oz513xipu.bkt.clouddn.com/"];
    NSURL *url = [[NSBundle mainBundle] URLForResource:@"annualreport" withExtension:@"json"];
    NSData *data = [NSData dataWithContentsOfURL:url];
    NSString *str = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    [HandeAR setAnnualReport:str];
//    [HandeAR setLayoutTopHeight:64 bottomHeight:100];
    
    HandeARViewController *vc = [[HandeARViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark - HandeARDelegate
//触发分享
- (void)triggerShareAction:(NSData *)imageData {
    //开始分享
    
//    WXImageObject *ext = [WXImageObject object];
//    ext.imageData = imageData;
//
//    WXMediaMessage *message = [WXMediaMessage messageWithTitle:nil
//                                                   Description:nil
//                                                        Object:ext
//                                                    MessageExt:kMessageExt
//                                                 MessageAction:kMessageAction
//                                                    ThumbImage:nil
//                                                      MediaTag:kImageTagName];
//
//    SendMessageToWXReq* req = [SendMessageToWXReq requestWithText:nil
//                                                   OrMediaMessage:message
//                                                            bText:NO
//                                                          InScene:WXSceneSession];
//
//    [WXApi sendReq:req];
}

//识别到AR
- (void)didOnFoundAR {
    [self.navigationController setNavigationBarHidden:YES animated:YES];
}

//将要回到AR扫一扫
- (void)willShowARScan {
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}

//识别到二维码
- (void)didOnFoundQR:(NSString *)message {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"二维码" message:message delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [alert show];
}

- (void)onUnityException:(int)errorCode {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"网络错误" message:nil delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [alert show];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
}
@end
